package net.onceface.core.domain;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.onceface.core.domain.mappedsuper.TimeIntervalEntity;

@Entity
@Table(name="SYS_CLIENT")
public class Client extends TimeIntervalEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6423698828625705191L;
	
	/**
	 * 作为客户的人
	 * **/
	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "PERSON_ID")
	private Person person;

	/**
	 *  最后登录时间
	 */
	@Column(name = "LAST_LOGIN_TIME")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastLoginTime;

	/**
	 *  用户账户
	 */
	@Column(name = "USER_ACCOUNT")
	private String userAccount;

	/**
	 *  用户密码
	 */
	@Column(name = "USER_PASSWORD")
	private String userPassword;

	/**
	 *  排序
	 */
	@Column(name = "USER_DESC")
	private String userDesc;

	/**
	 *  头像
	 */
	@Column(name = "USER_AVATAR")
	private String userAvatar;

	/**
	 * 是否可用
	 */
	@Column(name = "DISABLED")
    private boolean disabled;
	
	/**
     * 描述
     */
    @Column(name = "DESCRIPTION")
    private String description;
    
    /**
     * 昵称
     */
    @Column(name="NICK")
    private String nick;
    
    /**
     * 加密盐值
     */
    @Column(name = "SALT")
    private String salt;
    
    /**
     * 最后修改人
     * **/
    @Column(name="MODIFY_OWER")
    private String modifyOwer;
    
	/**
	 *  最后修改时间
	 */
	@Column(name = "LAST_MODIFY_TIME")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastModifyTime;
	
	public static Client findByUserAccount(String userAccount){
		return getRepository().createJpqlQuery("SELECT _client FROM Client _client WHERE _client.userAccount = :userAccount")
				.addParameter("userAccount", userAccount)
				.singleResult();
	}

	public Person getPerson() {
		return person;
	}


	public void setPerson(Person person) {
		this.person = person;
	}


	public Date getLastLoginTime() {
		return lastLoginTime;
	}


	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}


	public String getUserAccount() {
		return userAccount;
	}


	public void setUserAccount(String userAccount) {
		this.userAccount = userAccount;
	}


	public String getUserPassword() {
		return userPassword;
	}


	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}


	public String getUserDesc() {
		return userDesc;
	}


	public void setUserDesc(String userDesc) {
		this.userDesc = userDesc;
	}


	public String getUserAvatar() {
		return userAvatar;
	}


	public void setUserAvatar(String userAvatar) {
		this.userAvatar = userAvatar;
	}


	public boolean isDisabled() {
		return disabled;
	}


	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}


	public String getDescription() {
		return description;
	}


	public void setDescription(String description) {
		this.description = description;
	}


	public String getNick() {
		return nick;
	}


	public void setNick(String nick) {
		this.nick = nick;
	}


	public String getModifyOwer() {
		return modifyOwer;
	}

	public void setModifyOwer(String modifyOwer) {
		this.modifyOwer = modifyOwer;
	}

	public Date getLastModifyTime() {
		return lastModifyTime;
	}


	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}
	
	public String getSalt() {
		return salt;
	}
	public void setSalt(String salt) {
		this.salt = salt;
	}


	@Override
	public String[] businessKeys() {
		// TODO Auto-generated method stub
		return null;
	}

}
